package com.deep.bilibili.config;

import com.deep.bilibili.interceptor.GlobalInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class WebConfig extends WebMvcConfigurationSupport {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/uploads/**").addResourceLocations("classpath:/uploads/");
        registry.addResourceHandler("/uploads/**").addResourceLocations("file:D:/Projects/Other/koa-demo/bilibili-upload/uploads/");
        registry.addResourceHandler("/live/**").addResourceLocations("file:D:/Projects/Other/koa-demo/bilibili-upload/live/");

        //需要配置1：----------- 需要告知系统，这是要被当成静态文件的！
        //第一个方法设置访问路径前缀，第二个方法设置资源路径
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/v2/api-docs").addResourceLocations("classpath:/META-INF/resources/");

//        registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
//        registry.addResourceHandler("/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/swagger-ui/**").addResourceLocations("classpath:/META-INF/resources/");

        //WebMvcConfigurer.super.addResourceHandlers(resourceHandlerRegistry);
        registry.addResourceHandler("doc.html").addResourceLocations("classpath*:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath*:/META-INF/resources/webjars/");
        registry.addResourceHandler("/api/doc/webjars/*").addResourceLocations("classpath*:/META-INF/resources/webjars/");

        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
        registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");

    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new GlobalInterceptor())
                .excludePathPatterns("/swagger-ui.html")
                .excludePathPatterns("/swagger-ui/index.html")
                .excludePathPatterns("/swagger-ui**/**")
                .excludePathPatterns("/webjars/**")
                .excludePathPatterns("/favicon.ico")
                .excludePathPatterns("/upload/**")
                .excludePathPatterns("/static/**")
                .excludePathPatterns("/admin/captcha")
                .excludePathPatterns("/admin/kaptcha2")
                .excludePathPatterns("/webjars/**")
                .excludePathPatterns("/doc.html")
                .addPathPatterns("/admin/**");
    }
}
